{{- $context := . }}
{{ $namespaces := list }}
{{- range $crd := $context.Values.userAuthn.internal.dexAuthenticatorCRDs }}
---
apiVersion: v1
kind: Secret
metadata:
  name: dex-authenticator-{{ $crd.name }}
  namespace: {{ $crd.namespace }}
  {{- include "helm_lib_module_labels" (list $context (dict "app" "dex-authenticator" "name" "credentials")) | nindent 2 }}
data:
  {{- if $crd.allowAccessToKubernetes }}
  client-secret: {{ $context.Values.userAuthn.internal.kubernetesDexClientAppSecret | b64enc }}
  {{- else }}
  client-secret: {{ $crd.credentials.appDexSecret | b64enc }}
  {{- end }}
  cookie-secret: {{ $crd.credentials.cookieSecret | b64enc }}

  {{- if not (has $crd.namespace $namespaces) }}
---
apiVersion: v1
kind: Secret
metadata:
  name: registry-dex-authenticator
  namespace: {{ $crd.namespace }}
  {{- include "helm_lib_module_labels" (list $context (dict "app" "dex-authenticator")) | nindent 2 }}
type: kubernetes.io/dockerconfigjson
data:
  .dockerconfigjson: {{ $context.Values.global.modulesImages.registry.dockercfg }}
    {{- $namespaces = append $namespaces $crd.namespace }}
  {{- end }}
{{- end }}
